/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-10-26
 * Time:6:31
 */

import java.util.*;
public class Main {

    int num;
    String pre_order, in_order;

    class Node {
        char data;
        Node left = null, right = null;
        public Node(char data) {
            this.data = data;
        }
    }

    public static void main(String[] args) throws Exception{
        Main main = new Main();
        Scanner scanner = new Scanner(System.in);
        main.num = scanner.nextInt();
        scanner.nextLine();
        main.pre_order = scanner.nextLine();
        main.in_order = scanner.nextLine();
        Node root = main.CreatTree(0,main.num - 1, 0,main.num - 1);
        System.out.print(main.height(root));
    }

    public int height(Node root) {
        if (root == null)
            return 0;
        if (root.right == null && root.right == null)
            return 1;
        return Math.max(height(root.left), height(root.right)) + 1;
    }

    public Node CreatTree(int ps, int pe, int is, int ie) {
        int pl = pe - ps;
        int il = ie - is;
        if (pl < 0 || il < 0) {
            return null;
        }
        if (pl == 0 || il == 0) {
            return new Node(pre_order.charAt(ps));
        }
        Node node = new Node(pre_order.charAt(ps));
        int mid = in_order.indexOf(pre_order.charAt(ps));
        int len = mid - is;
        node.left = CreatTree(ps+1, ps + len, is, mid - 1);
        node.right = CreatTree(ps + len + 1, pe, mid + 1, ie);
        return node;
    }

}
